package com.hfut.manage.service.impl;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.hfut.manage.pojo.Family;
import com.hfut.manage.mapper.FamilyMapper;
import com.hfut.manage.service.IFamilyService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;


@Service
public class FamilyServiceImpl extends ServiceImpl<FamilyMapper, Family> implements IFamilyService {

    @Autowired
    private FamilyMapper familyMapper;
    
    @Transactional
    public boolean saveFamily(Family familyView) {
        List<Family> familyQuery =  this.lambdaQuery().eq(Family::getId, familyView.getId()).list();
        int result = 0;
        if(familyQuery.isEmpty()) {
            result =  familyMapper.insertFamily(familyView);
        }
        else {
            result = familyMapper.updateFamily(familyView);
        }
        return result>0;
    }

    
    @Transactional
    public boolean deleteFamily(Long id) {
        int result = familyMapper.deleteFamily(id);
        return result > 0;
    }

}
